package demo1;

interface ID {
    void TEST();
}

public class Anonymous {
    public static int a=10;
    public void test() {
        System.out.println("Anonymous类的test方法被调用");
        a = 20;
    }

    public static void main(String[] args) {
        //Test1();
        Test2();
    }
    public static void Test2() {
        //定义匿名内部类
        new ID(){
            @Override
            public void TEST() {
                System.out.println("重写接口的方法");
            }
        }.TEST();
    }
    public static void Test1() {
        //定义匿名内部类
        new Anonymous(){
            public static int b = 10;
            //b = 1;
            @Override
            public void test() {
                a = 20;
                b = 20;
                System.out.println("重写的test方法被调用");
            }
        }.test();
    }
}
